package com.ktjy.controller;

import com.ktjy.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    Logger logger = LoggerFactory.getLogger(HelloController.class);

    @RequestMapping("/list")
    public String list(HttpServletRequest request, Model model) {
        String name = request.getParameter("name");
        String age = request.getParameter("age");

        List<User> list = new ArrayList<User>();
        list.add(new User(1,"傻琦",18));
        list.add(new User(2,"傻琦1",13));
        list.add(new User(3,"傻琦3",14));

        model.addAttribute("list", list);

        logger.info("list方法进来了，name={}，age={}", name, age);
        return "list";
    }

    @RequestMapping("/view")
    public String view(@RequestParam("id") Integer id) {
        logger.info("view方法id={}", id);
        return null;
    }

    @RequestMapping("/add")
    public String add() {
        return "add";
    }

    @RequestMapping("/save")
    public String save(User user) {
        logger.info("save方法进来了name={}，age={}", user.getName(), user.getAge());
        return null;
    }

}
